# Methods added to this helper will be available to all templates in the application.
module Admin::PostsHelper
  def local_date(date)
    if !date.nil?
      date = date.since(3600*16)
      date.year.to_s + "-" + date.month.to_s + "-" + date.day.to_s + " " + date.hour.to_s + ":" + date.min.to_s 
    end
  end
  
  def post_reply_delete_path(reply)
    html = ''
    if reply.post.class == CommonPost
      html << link_to('删除', community_post_reply_path(reply.post.community.district, reply.post.community, reply.post, reply), :confirm => "Are you sure?", :method => :delete)
    end
    if reply.post.class == GroupPost
      html << link_to('删除', group_post_reply_path(reply.post.group, reply.post, reply), :confirm => "Are you sure?", :method => :delete)
    end
    if reply.post.class == SitePost
      html << link_to('删除', site_post_reply_path(reply.post.site, reply.post, reply), :confirm => "Are you sure?", :method => :delete)
    end
    html
  end
  
  def url_for_post(post)
    if post.class == CommonPost
      return admin_common_post_path(post.community.district, post.community, post)
    end
    if post.class == GroupPost
      return admin_group_post_path(post.group, post)
    end
    if post.class == SitePost
      return admin_site_post_path(post.site, post)
    end
  end
  
  def post_path(post)
    html = ''
    
    html << link_to("#{post.title}", url_for_post(post))
  end
end
